<?php

namespace Drinkiit\BlogBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Drinkiit\BlogBundle\Form\ContactType;
use Drinkiit\BlogBundle\Controller\MailController;

class ContactController extends Controller
{
	
	public function indexAction($section = 'contact')
	{
		$form = $this->createForm(new ContactType);
		
		if( $this->get('request')->getMethod() == 'POST' )
        {
            $form->bindRequest($this->get('request'));

            if( $form->isValid() )
            {
				
				$mailing = new MailController() ;
				
				$sect = $form->get('section')->getData() ;
				$mail = $form->get('mail')->getData() ;
				$pseu = $form->get('pseudo')->getData() ;
				$mess = $form->get('message')->getData() ;
				
				//return $mailing->contactAction($sect, $mail, $pseu, $mess) ;
				return $this->redirect( $this->generateUrl('visitor_contact_envoie', array(
					'section' => $sect,
					'mail' => $mail,
					'pseudo' => $pseu,
					'mess' => $mess,
				) ) ) ;
			}
			
		}
		
        return $this->render('DrinkiitBlogBundle:Visitor:Contact.html.twig', array(
			'form' => $form->createView(),
			'section' => $section,
			'titre' => 'Une question, une suggestion?',
		));
	}
	
	public function contactAction()
	{
        return $this->indexAction('contact');
	}
	
	public function suggestionAction()
	{
        return $this->indexAction('suggestion');
	}
}
